﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WickedFlame.Core.Layers;

namespace WickedFlame.Core.History
{
    public class LayerDeleteCommand : HistoryCommand
    {
        CanvasLayer layer;
        DrawingCanvas canvas;
        int indexInCanvas = -1;

        public LayerDeleteCommand(CanvasLayer layer, DrawingCanvas canvas, int layerIndex)
            : base(layerIndex)
        {
            Title = "Layer deleted";
            this.layer = layer;
            this.canvas = canvas;
        }

        public override void Undo(ShapeList list)
        {
            if (indexInCanvas < 0)
                indexInCanvas = LayerIndex + 1;
            canvas.Layers.Insert(LayerIndex, layer);
            canvas.Children.Insert(indexInCanvas, layer);
        }

        public override void Redo(ShapeList list)
        {
            if (indexInCanvas < 0)
                indexInCanvas = canvas.Children.IndexOf(layer);
            canvas.Children.Remove(layer);
            canvas.Layers.Remove(layer);
        }
    }
}
